// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";

import "./interfaces/IACLManager.sol";

contract ACLManager is AccessControl, IACLManager {
    bytes32 public constant override PROTOCOL_ADMIN_ROLE = keccak256("PROTOCOL_ADMIN");
    bytes32 public constant override PROTOCOL_TRADER_ROLE = keccak256("PROTOCOL_TRADER");

    constructor(address newProtocolAdmin) {
        require(newProtocolAdmin != address(0), "ACLManger: constructor: newProtocolAdmin can't be zero");
        _registerAdmin(newProtocolAdmin);
    }

    function registerAdmins(address[] calldata admins) external override onlyRole(PROTOCOL_ADMIN_ROLE) {
        for (uint256 i; i < admins.length; i++) {
            _registerAdmin(admins[i]);
        }
    }

    function registerTraders(address[] calldata traders) external override onlyRole(PROTOCOL_ADMIN_ROLE) {
        for (uint256 i; i < traders.length; i++) {
            _grantRole(PROTOCOL_TRADER_ROLE, traders[i]);
        }
    }

    function isProtocolAdmin(address protocolAdmin) external view override returns (bool) {
        return hasRole(PROTOCOL_ADMIN_ROLE, protocolAdmin);
    }

    function isProtocolTrader(address protocolTrader) external view override returns (bool) {
        return hasRole(PROTOCOL_TRADER_ROLE, protocolTrader);
    }

    function _registerAdmin(address newProtocolAdmin) private {
        _grantRole(PROTOCOL_ADMIN_ROLE, newProtocolAdmin);
        _grantRole(PROTOCOL_TRADER_ROLE, newProtocolAdmin);
    }
}
